import { fromJS } from 'immutable'
import * as actionTypes from './actionTypes'

const defaultState = fromJS({
  TopList: [],
  articleList: [],
  imgList: [],
  RecommendList: [],
  WriterList: [],
  scrollShow: false
})

const reducer = (state = defaultState, action) => {
  switch (action.type) {
    case actionTypes.INIT_TOP_LIST:
      // console.log(action)
      return state.merge({
        TopList: fromJS(action.data.TopList),
        articleList: fromJS(action.data.articleList),
        imgList: fromJS(action.data.imgList),
        RecommendList: fromJS(action.data.RecommendList),
        WriterList: fromJS(action.data.WriterList),
      })
    case actionTypes.LOAD_MORE_LIST:
      // console.log(action)
      return state.set('articleList', state.get('articleList').concat(fromJS(action.data.articleList)))
    case actionTypes.CHANGE_SCROLL:
      // console.log(action)
      return state.set('scrollShow', action.flag)
    default:
      break;
  }
  return state
}

export default reducer